<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"he7009.gitee.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="查看镜像列表 docker images		或者		docker image list image 创建  docker pull 直接拉取 image dockerfile 构建 基于已有容器创建 导入本地 image  docker pull# 命令格式 docker [image] pull NAME [ :TAG]  # NAME：镜像名称 # TAG：镜像标签 # 如果不显式指定TAG,">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker-image 常用命令">
<meta property="og:url" content="https://he7009.gitee.io/2021/03/27/docker/docker-image-chang-yong-ming-ling/index.html">
<meta property="og:site_name" content="he7009">
<meta property="og:description" content="查看镜像列表 docker images		或者		docker image list image 创建  docker pull 直接拉取 image dockerfile 构建 基于已有容器创建 导入本地 image  docker pull# 命令格式 docker [image] pull NAME [ :TAG]  # NAME：镜像名称 # TAG：镜像标签 # 如果不显式指定TAG,">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-27T10:25:10.000Z">
<meta property="article:modified_time" content="2021-03-27T10:27:44.300Z">
<meta property="article:author" content="he7009">
<meta property="article:tag" content="image">
<meta property="article:tag" content="镜像">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://he7009.gitee.io/2021/03/27/docker/docker-image-chang-yong-ming-ling/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Docker-image 常用命令 | he7009</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="he7009" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">he7009</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">天行健，君子以自强不息</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tag fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://he7009.gitee.io/2021/03/27/docker/docker-image-chang-yong-ming-ling/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="he7009">
      <meta itemprop="description" content="Go、PHP、Mysql、Redis、Linux、Shell、Nginx—知识分享">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="he7009">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Docker-image 常用命令
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-03-27 18:25:10 / 修改时间：18:27:44" itemprop="dateCreated datePublished" datetime="2021-03-27T18:25:10+08:00">2021-03-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="查看镜像列表"><a href="#查看镜像列表" class="headerlink" title="查看镜像列表"></a>查看镜像列表</h2><hr>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">docker images		或者		docker image list<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h2 id="image-创建"><a href="#image-创建" class="headerlink" title="image 创建"></a>image 创建</h2><hr>
<ol>
<li>docker pull 直接拉取 image</li>
<li>dockerfile 构建</li>
<li>基于已有容器创建</li>
<li>导入本地 image</li>
</ol>
<h3 id="docker-pull"><a href="#docker-pull" class="headerlink" title="docker pull"></a>docker pull</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 命令格式</span>
docker <span class="token punctuation">[</span>image<span class="token punctuation">]</span> pull NAME <span class="token punctuation">[</span> :TAG<span class="token punctuation">]</span>

<span class="token comment"># NAME：镜像名称</span>
<span class="token comment"># TAG：镜像标签</span>
<span class="token comment"># 如果不显式指定TAG, 则默认会选择latest标签</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="dockerfile-构建"><a href="#dockerfile-构建" class="headerlink" title="dockerfile 构建"></a>dockerfile 构建</h3><p>部分指令：</p>
<table>
<thead>
<tr>
<th align="center">指令</th>
<th align="center">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="center">FROM</td>
<td align="center">指定所创建镜像的基础镜像</td>
</tr>
<tr>
<td align="center">LABEL</td>
<td align="center">LABEL 指令可以为生成的镜像添加元数据标签信息</td>
</tr>
<tr>
<td align="center">ARG</td>
<td align="center">定义创建镜像过程中使用的变量，镜像创建成功后变量将不再存在</td>
</tr>
<tr>
<td align="center">ENV</td>
<td align="center">指定环境变量，可以被后续的 RUN 指令使用，在镜像启动的容器中也会存在</td>
</tr>
<tr>
<td align="center">ENTRYPOINT</td>
<td align="center">指定镜像的默认入口命令</td>
</tr>
<tr>
<td align="center">WORKDIR</td>
<td align="center">为后续的 RUN、CMD、ENTRYPOINT 指令配置工作目录</td>
</tr>
<tr>
<td align="center">RUN</td>
<td align="center">运行指定命令</td>
</tr>
<tr>
<td align="center">CMD</td>
<td align="center">容器启动后默认执行的命令</td>
</tr>
<tr>
<td align="center">ADD</td>
<td align="center">添加内容到镜像；支持本地文件的相对路径和绝对路径，也可以是URL</td>
</tr>
<tr>
<td align="center">COPY</td>
<td align="center">复制本地主机内容到镜像</td>
</tr>
<tr>
<td align="center">EXPOSE</td>
<td align="center">声明服务监听的端口；只是声明并没有做端口映射</td>
</tr>
</tbody></table>
<p>示例：</p>
<pre class="line-numbers language-dockerfile" data-language="dockerfile"><code class="language-dockerfile">FROM php:7.4-fpm-alpine

RUN sed -i &quot;s&#x2F;dl-cdn.alpinelinux.org&#x2F;mirrors.aliyun.com&#x2F;g&quot; &#x2F;etc&#x2F;apk&#x2F;repositories \
  &amp;&amp; apk update \
  &amp;&amp; apk --no-cache add tzdata \
  &amp;&amp; cp &quot;&#x2F;usr&#x2F;share&#x2F;zoneinfo&#x2F;Asia&#x2F;Shanghai&quot; &#x2F;etc&#x2F;localtime \
  &amp;&amp; echo &quot;Asia&#x2F;Shanghai&quot; &gt; &#x2F;etc&#x2F;timezone \
  &amp;&amp; apk add --no-cache --virtual .build-deps autoconf g++ libtool make linux-headers bzip2-dev libzip-dev

ADD .&#x2F;install-php-extensions &#x2F;usr&#x2F;local&#x2F;bin&#x2F;

RUN chmod +x &#x2F;usr&#x2F;local&#x2F;bin&#x2F;install-php-extensions &amp;&amp; sync &amp;&amp; \
    install-php-extensions rdkafka pcntl swoole redis bcmath bz2 gd \
    gettext imagick mcrypt memcached mongodb mysqli pcntl \
    pdo_mysql shmop soap sockets sysvmsg sysvsem sysvshm xdebug \
    xmlrpc zip

RUN mkdir &#x2F;tmp&#x2F;extensions

WORKDIR &#x2F;tmp&#x2F;extensions

RUN mkdir &#x2F;tmp&#x2F;scws \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-1.2.3.tar.bz2 \
    &amp;&amp; tar -xjf &#x2F;tmp&#x2F;extensions&#x2F;scws-1.2.3.tar.bz2 -C &#x2F;tmp&#x2F;scws --strip-components&#x3D;1 \
    &amp;&amp; cd &#x2F;tmp&#x2F;scws  \
    &amp;&amp; .&#x2F;configure --prefix&#x3D;&#x2F;usr&#x2F;local&#x2F;scws  \
    &amp;&amp; make &amp;&amp; make install  \
    &amp;&amp; ( cd phpext &amp;&amp; phpize &amp;&amp; .&#x2F;configure --with-scws&#x3D;&#x2F;usr&#x2F;local&#x2F;scws &amp;&amp; make &amp;&amp; make install ) \
    &amp;&amp; cd &#x2F;usr&#x2F;local&#x2F;scws&#x2F;etc \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; wget http:&#x2F;&#x2F;www.xunsearch.com&#x2F;scws&#x2F;down&#x2F;scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-gbk.tar.bz2 \
    &amp;&amp; tar -xvjf scws-dict-chs-utf8.tar.bz2 \
    &amp;&amp; docker-php-ext-enable scws \
    &amp;&amp; rm -rf &#x2F;tmp&#x2F;*

ENV LD_PRELOAD &#x2F;usr&#x2F;lib&#x2F;preloadable_libiconv.so php<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>docker build 镜像</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 命令格式</span>
docker build <span class="token punctuation">[</span>OPTIONS<span class="token punctuation">]</span> <span class="token environment constant">PATH</span> <span class="token punctuation">[</span> URL I -

<span class="token comment"># 主要 OPTIONS</span>
<span class="token comment"># -build-arg : 为 dockerfile 中的 arg 变量赋值</span>
<span class="token comment"># -f : 指定 dockerfile 名称</span>
<span class="token comment"># -t : 指定 image 标签</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>


<h3 id="基于已有容器创建"><a href="#基于已有容器创建" class="headerlink" title="基于已有容器创建"></a>基于已有容器创建</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 命令格式</span>
docker <span class="token punctuation">[</span>container<span class="token punctuation">]</span> commit <span class="token punctuation">[</span>OPTIONS<span class="token punctuation">]</span> CONTAINER <span class="token punctuation">[</span>REPOSITORY <span class="token punctuation">[</span>:TAG<span class="token punctuation">]</span><span class="token punctuation">]</span>

<span class="token comment"># 主要OPTIONS</span>
<span class="token comment"># -c: 作者信息</span>
<span class="token comment"># -m: 提交信息</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<h3 id="导入本地-image"><a href="#导入本地-image" class="headerlink" title="导入本地 image"></a>导入本地 image</h3><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 导出镜像</span>
docker save -o 导出镜像名称 镜像名称<span class="token punctuation">[</span>:镜像标签<span class="token punctuation">]</span>

<span class="token comment"># 载入镜像</span>
docker load -i 本地镜像文件

<span class="token comment"># 或者</span>
docker load <span class="token operator">&lt;</span> 本地镜像文件 
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>


<h2 id="image-删除"><a href="#image-删除" class="headerlink" title="image 删除"></a>image 删除</h2><hr>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token comment"># 删除单个镜像</span>
docker rmi 镜像名称:镜像标签		或者		docker rmi 镜像ID

<span class="token comment"># 按条件筛选之后删除</span>
docker rmi <span class="token variable"><span class="token variable">`</span>docker images <span class="token operator">|</span> <span class="token function">grep</span> xxxxx <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'&#123;print <span class="token variable">$3</span>&#125;'</span><span class="token variable">`</span></span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>



    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/image/" rel="tag"># image</a>
              <a href="/tags/%E9%95%9C%E5%83%8F/" rel="tag"># 镜像</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/11/mysql/mysql-pei-zhi-qi-dong-xi-tong-bian-liang/" rel="prev" title="Mysql 配置、启动、系统变量">
      <i class="fa fa-chevron-left"></i> Mysql 配置、启动、系统变量
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/03/27/docker/docker-container-chang-yong-ming-ling/" rel="next" title="Docker-Container 常用命令">
      Docker-Container 常用命令 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F%E5%88%97%E8%A1%A8"><span class="nav-number">1.</span> <span class="nav-text">查看镜像列表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#image-%E5%88%9B%E5%BB%BA"><span class="nav-number">2.</span> <span class="nav-text">image 创建</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-pull"><span class="nav-number">2.1.</span> <span class="nav-text">docker pull</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#dockerfile-%E6%9E%84%E5%BB%BA"><span class="nav-number">2.2.</span> <span class="nav-text">dockerfile 构建</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9F%BA%E4%BA%8E%E5%B7%B2%E6%9C%89%E5%AE%B9%E5%99%A8%E5%88%9B%E5%BB%BA"><span class="nav-number">2.3.</span> <span class="nav-text">基于已有容器创建</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%BC%E5%85%A5%E6%9C%AC%E5%9C%B0-image"><span class="nav-number">2.4.</span> <span class="nav-text">导入本地 image</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#image-%E5%88%A0%E9%99%A4"><span class="nav-number">3.</span> <span class="nav-text">image 删除</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">he7009</p>
  <div class="site-description" itemprop="description">Go、PHP、Mysql、Redis、Linux、Shell、Nginx—知识分享</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">9</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">he7009</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
